﻿using RBAC.Repository.RabbitInterfae;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Traceability.Domain;
using Traceability.Service.Interfae;

namespace Traceability.Service.Impl
{
    public class HealthService : IHealthService
    {
        private readonly IHealthRepository _healrepository;
        public HealthService(IHealthRepository healrepository)
        {
            _healrepository= healrepository;
        }
        /// <summary>
        /// 添加保健信息
        /// </summary>
        /// <param name="health"></param>
        /// <returns></returns>
        public async Task<int> AddHealth(Health health)
        {
           return await _healrepository.AddAsync(health);
        }
        /// <summary>
        /// 删除保健信息
        /// </summary>
        /// <param name="hid"></param>
        /// <returns></returns>
        public async Task<int> DelHealth(int hid)
        {
            var dels = await _healrepository.GetModelsAsync(hid);
            dels.HealthDel = true;
            dels.delDate = DateTime.Now;
            dels.delName = "王宏";
            return await _healrepository.UpdateAsync(dels);
        }
        /// <summary>
        /// 显示保健信息
        /// </summary>
        /// <param name="bath"></param>
        /// <returns></returns>
        public async Task<List<Health>> GetHealth(string bath)
        {
          var listobj=from a in await _healrepository.GetAllAsync()
                      where !a.HealthDel&&a.Batch==bath
                      select a;
            return listobj.ToList();
        }
        /// <summary>
        /// 反填保健信息
        /// </summary>
        /// <param name="hid"></param>
        /// <returns></returns>
        public async Task<Health> GetHealthBy(int hid)
        {
            return await _healrepository.GetModelsAsync(hid);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="health"></param>
        /// <returns></returns>
        public async Task<int> UpdateHealth(Health health)
        {

            health.updateDate = DateTime.Now;
            health.updateName = "李四";
            return await _healrepository.UpdateAsync(health);
        }
    }
}
